package com.ym.producer.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {

    private static final int corePoolSite = 5;
    private static final int maxPoolSite = 10;
    private static final int queueCapacity = 25;

    // 创建调度器
    @Bean(name = "taskExecutor")
    public ThreadPoolTaskExecutor getThreadPoolExecutorInstance() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSite);
        executor.setMaxPoolSize(maxPoolSite);
        executor.setQueueCapacity(queueCapacity);
        executor.setThreadNamePrefix("Async_");
        executor.initialize();
        return executor;
    }
}
